package com.wtwd.device.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.device.dao.WebMedalMapper;
import com.wtwd.device.dao.WebMedalTypeMapper;
import com.wtwd.device.model.entity.MedalType;
import com.wtwd.device.service.WebMedalTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mjy
 * @since 2022-04-11
 */
@Service
public class WebMedalTypeServiceImpl implements WebMedalTypeService {

    @Autowired
    private WebMedalTypeMapper medalTypeMapper;

    @Autowired
    private WebMedalMapper medalMapper;

    @Override
    public IPage queryMedalTypePage(Page page) {
        return new LambdaQueryChainWrapper<>(medalTypeMapper)
                .orderByDesc(MedalType::getId)
                .page(page);
    }

    @Override
    public Integer addMedalType(MedalType medalType) {
        return medalTypeMapper.insert(medalType);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Integer deleteMedalType(Long medalTypeId) {
        medalMapper.deleteByMedalTypeId(medalTypeId);
        return medalTypeMapper.deleteById(medalTypeId);
    }
}
